package com.jackrain.nea.oms.task;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jackrain.nea.config.PropertiesConf;
import com.jackrain.nea.oms.services.SendMqServies;
import com.jackrain.nea.util.ApplicationContextHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class AutoSendStockCreat {
    @Autowired
    private PropertiesConf pconf;
    @Autowired
    private SendMqServies sendMqServies;

    public void getScheduledExecutorSendA() {
        log.debug("AutoMotThreads AutoSendStockCreat started !!!");
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    String jdStockTopic = pconf.getProperty("ons.jdStockTopic");
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("PLATFORM",4);
                    jsonObject.put("SELLER_NICK","乔德家纺旗舰店");
                    jsonObject.put("OUTSKUID","26859719997");
                    jsonObject.put("SYNCNUM",66L);
                    JSONArray jsonArray = new JSONArray();
                    jsonArray.add(jsonObject);
                    JSONObject returnObj = new JSONObject();
                    returnObj.put("data",jsonArray);
                    sendMqServies.sendMqObj(returnObj,jdStockTopic,"qiaode");
                } catch (Exception e) {
                    e.printStackTrace();
                    // 执行任务错误,将日志记录
                }
            }
        };
        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();
        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
        // 正式 要延迟适当时间,以便时间初始化赋值
        service.scheduleAtFixedRate(runnable, 10, pconf.getPropertyInt("ons.deliceryTime"), TimeUnit.SECONDS);
    }
}
